package boot3.service.impl;

import boot3.mapper.MessageMapper;
import boot3.pojo.Message;
import boot3.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageMapper messageMapper;
    @Override
    public List<Message> getAllMessage() {
        return messageMapper.getAllMessage();
    }

    @Override
    public Boolean setMessage(Message message) {
        //获取当前所有的消息
        int length = messageMapper.getAllMessage().size();
        int number=messageMapper.getAllMessage().isEmpty()?0:Integer.parseInt(messageMapper.getAllMessage().get(length-1).getMessage_id());
        message.setMessage_id(String.valueOf(number+1));
        return messageMapper.setMessage(message);
    }

    @Override
    public Boolean deleteMessage(String message_id) {
        return messageMapper.deleteMessage(message_id);
    }

    @Override
    public List<Message> getMessageByReceiverId(String receiver_id) {
        return messageMapper.getMessageByReceiverId(receiver_id);
    }

    @Override
    public Boolean updateMessageWatch(String message_id) {
        return messageMapper.updateMessageWatch(message_id);
    }

    @Override
    public Boolean updateMessageWatchByRS(String receiver_name, String sender_name) {
        return messageMapper.updateMessageWatchByRS(receiver_name,sender_name);
    }
}
